package sanshui.system.trade.service;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;
import sanshui.system.trade.common.CommonResponse;
import sanshui.system.trade.common.TradeType;
import sanshui.system.trade.db.entity.*;
import sanshui.system.trade.db.mapper.StockTblAllBasicMapper;
import sanshui.system.trade.db.mapper.StockTblDailyRtMapper;
import sanshui.system.trade.db.mapper.StockTblFavoriteBasicMapper;
import sanshui.system.trade.db.mapper.TradeTargetCodeMapper;
import sanshui.system.trade.pojo.StockInfoVo;
import sanshui.system.trade.util.StockFilterUtil;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class StockInfoServiceImpl extends ServiceImpl<StockTblDailyRtMapper, StockTblDailyRt> implements IStockInfoService {

    @Resource
    TradeTargetCodeMapper targetCodeMapper;
    @Resource
    StockTblAllBasicMapper stockTblAllBasicMapper;
    @Resource
    StockTblDailyRtMapper dailyRtMapper;

    @Override
    public List<TradeTargetCode> findTargetStock(Long workerId) {
        TradeTargetCodeExample example = new TradeTargetCodeExample();
        TradeTargetCodeExample.Criteria criteria = example.createCriteria();
        criteria.andDelFlgEqualTo(TradeType.DelFlg.EXIT.getCode());
        criteria.andTargetWorkIdEqualTo(workerId);
        return targetCodeMapper.selectByExample(example);
    }

    @Override
    public List<StockInfoVo> findAllStockInfo() {
        StockTblAllBasicExample stockTblAllBasicExample = new StockTblAllBasicExample();
        List<StockInfoVo> rls = new ArrayList<>();

        List<StockTblAllBasic> stockTblAllBasics = stockTblAllBasicMapper.selectByExample(stockTblAllBasicExample);
        for (StockTblAllBasic stockTblAllBasic : stockTblAllBasics) {
            StockInfoVo stockInfoVo = new StockInfoVo();
            stockInfoVo.setTsCode(stockTblAllBasic.getTsCode());
            stockInfoVo.setTsName(stockTblAllBasic.getName());
            rls.add(stockInfoVo);
        }
        return rls;
    }

    @Override
    public boolean batchInsertRt(List<StockTblDailyRt> list, int batchSize) {
        return saveBatch(list, batchSize);
    }
}
